home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- *
- * Apple Developer Technical Support
- *
- * Edition publishing routines
- *
- * Program: EditionSample
- * File: Publish.c - C Source
- *
- * by: C.K. Haun <TR>
- *
- * Copyright © 1990,1991 Apple Computer, Inc.
- * All rights reserved.
- *
- *------------------------------------------------------------------------------
- * Publish handles most of the publishing housekeeping. There is (are)
- * some routines that are common to both publishing and subscribing, they
- * are located in Subscribe.c
- *----------------------------------------------------------------------------*/
- #define __PUBLISH__
-
- #pragma segment Publish
- #pragma load "EdSampheaders" /* see the Buildheaders.c file */
-
- #include "EdSampdefines.h"
-
- /* prototypes */
- OSErr CreatePublisher(OSType typeToMake,Boolean fromEvent,AliasHandle theAlias);
- PicHandle MyMakePicture(Rect *thisRect);
- OSErr MyWriteSection(SectionHandle secHandle, Handle theData, OSType theType);
- OSErr MyUpdateEdition(SectionHandle theSection);
- void StorePublisher(windowCHandle shortName, SectionHandle storeSection, Rect *inRect, textSectionHandle textIn, OSType typeIn);
- WindowPtr FindSection(SectionHandle inSection);
- pascal OSErr AEWriteSectionHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
- pascal OSErr AECreatePubHandler(AppleEvent *messagein, AppleEvent *reply, long refIn);
- pascal short ExpOptHook(short itemOffset, short itemHit, DialogPtr theDialog, Ptr yourDataPtr);
- pascal Boolean ExpOptFilter(DialogPtr theDialog, EventRecord *theEvent, short itemOffset, short *itemHit, Ptr yourDataPtr);
- textSectionHandle GetTextSection(windowCHandle shortName, SectionType what);
- textSectionHandle TextSectionFromSecHandle(SectionHandle theSection);
-
- /* external references */
- extern void ShowMe(Str255 in, OSErr aevtErr);
- extern void ChangePlane(WindowPtr twindow);
- extern void MyCancelSection(SectionHandle inSection, WindowPtr theWindow);
- extern OSErr GetSectionHandleFromEvent(AppleEvent *AEin, SectionHandle *theSection);
- extern Rect selectRect;
- extern WindowPtr gCurrentWindow;
- extern void SetMyCursor(short myCurs);
- extern void SwitchChecks(short itemNow);
- extern void AppendString(Str255 target, Str255 appendIt);
- extern Boolean gShowPub;
- extern Boolean gShowSub;
- extern Boolean gHasSelection;
- extern ProcessSerialNumber gOurSN; /* serial number of this process (us) */
- extern Boolean gShowingAll;
- /* globals */
- SectionHandle gSecHandle;
- EditionRefNum gEdRefNum;
- EditionContainerSpec gEdSpec;
- unsigned long gSectionID = 1;
-
- /* CreatePublisher takes the currently selected area in the current window
- * and creates an edition. It starts by setting up some default data
- * structures and creating a preview picture.
- * Then the user is prompted for a location and name for the publisher
- * with the NewPublisherDialog. If the user clicks OK, then the edition
- * is created and the section handle and rectangle for this edition is
- * stored in my data structure for this window, and the first edition
- * is written out.
- */
-
- OSErr CreatePublisher(OSType typeToMake,Boolean fromEvent,AliasHandle theAlias)
- {
- NewPublisherReply myreply;
- Handle theData;
- Rect currentRect;
- textSectionHandle pubText;
- Str31 addPub;
- static pubCounter;
- OSErr myErr;
- windowCHandle shortName;
- extern Point expPoint;
- extern Boolean gExpanded;
- /* we're publishing from the current, topmost window */
- shortName = (windowCHandle)GetWRefCon(gCurrentWindow);
- HLock((Handle)shortName);
- switch (typeToMake) {
- case 'PICT':
- currentRect = (*shortName)->selectionRect;
- /* take the rectangle we currently have selected, and make it a picture */
- InsetRect(¤tRect, 4, 4); /* take away the bordering outset */
- theData = (Handle)MyMakePicture(¤tRect); /* my function to make a PICT */
- /* Set up the reply record for the publisher dialog. */
- myreply.usePart = false; /* must be false */
- myreply.previewFormat = 'PICT'; /* type of data we're publishing */
- myreply.preview = theData; /* handle to the pict data */
- break;
- case 'TEXT':
- /* make text preview */
- myreply.usePart = false; /* must be false */
- myreply.previewFormat = 'TEXT'; /* type of data we're publishing */
- pubText = GetTextSection(shortName, stPublisher);
- HLock((Handle)pubText);
- theData = (*pubText)->theText; /* duplicate the text for our preview */
- HandToHand(&theData);
- if (GetHandleSize(theData) > 200)
- SetHandleSize(theData, 200);
-
- myreply.preview = theData;
- break;
- case kCustomType:
- break;
- }
- GetLastEditionContainerUsed(&gEdSpec); /* get a new edition containter. */
- /* this call gives us a duplicate of the last used, or if none used last, gives */
- /* us a default container */
- /* BY THE WAY - the 'last used' means the last used by the Edition Manager, not */
- /* by your application, so if you don't specify a default name then the */
- /* name that comes up as the default for the edition may be the last */
- /* name used by another application, or from the last time your */
- /* application was run. So if you are concerned about this (like you */
- /* think it may confuse the user) set your own default */
- /* As a sidelight (and not guarenteed) an alias to the last edition container used */
- /* is stored in the 'Preferences' folder in the system folder */
- myreply.container = gEdSpec; /* put our file spec in the container to be filled */
- /* now set the default name to be the same as the window plus a count */
- GetWTitle(gCurrentWindow, &myreply.container.theFile.name);
- GetIndString(addPub, kGeneralStrings, 1);
- AppendString(myreply.container.theFile.name, addPub);
- NumToString((long)((*shortName)->numPubs) + 1, addPub);
- AppendString(myreply.container.theFile.name, addPub);
- if(!fromEvent){
- if (!gExpanded)
- myErr = NewPublisherDialog(&myreply); /* run the dialog */
- else
- {
- ExpDlgHookUPP dhUPP = NewExpDlgHookProc(ExpOptHook);
- ExpModalFilterUPP mfUPP = NewExpModalFilterProc(ExpOptFilter);
- myErr = NewPublisherExpDialog(&myreply, expPoint, kExpandedDITL, dhUPP, mfUPP, nil);
- DisposeRoutineDescriptor(dhUPP);
- DisposeRoutineDescriptor(mfUPP);
- }
-
- if (myErr) {
- ShowMe("\pPubisher dialog", myErr);
- return;
- }
- if (myreply.canceled) { /* they canceled. release memory, reset our */
- /* menus and cursors, and go away */
- switch (typeToMake) {
- case 'PICT':
- KillPicture((PicHandle)theData);
- InvalRect(&(*shortName)->selectionRect);
- gShowPub = false;
- (*shortName)->hasSelection = false;
- SetMyCursor(0);
- SwitchChecks(kSelectStuff);
-
- break;
- case 'TEXT':
- DisposeHandle((*pubText)->theText);
- DisposeHandle((Handle)pubText);
- DisposeHandle(theData);
- break;
- case kCustomType:
- break;
- }
- return;
- }}
- /* They clicked Publish. First create the container (file) to hold the data */
- /* See if thye are replacing a file */
- if (!myreply.replacing) {
- if (myErr = CreateEditionContainerFile(&myreply.container.theFile, 'CKH6', myreply.container.theFileScript)) {
- ShowMe("\pCreateEditionContainerFIle", myErr);
- return;
- }
- } else {
- /* they agreed to delete an existing file. Kill it. */
- FSpDelete(&myreply.container.theFile);
- if (myErr = CreateEditionContainerFile(&myreply.container.theFile, 'CKH6', myreply.container.theFileScript)) {
- ShowMe("\pCreateEditionContainerFIle", myErr);
- return;
-
- }
- }
- /* now create the section record to describe this data to the edition manager */
- /* The section handle that is returned by this function will be the */
- /* way that you will reference this edition for as long as the edition is */
- /* active. */
- /* The main way you'll keep track is through the section ID number. */
- /* In this case, I have a base ID number for the window, and I just increment */
- /* my general ID (gSectionID) every time I create an edition, and add it to the window ID. */
- if (GetHandleSize((Handle)(*shortName)->fileAliasHandle) == 0) {
- myErr = NewSection(&myreply.container, nil, stPublisher, (*shortName)->windowID + gSectionID, pumOnSave, &gSecHandle);
- /* nil for sectionDocument if it's never been saved */
- } else {
- /* if the file has been saved once, then we can store a reference to the 'parent' file */
- /* in the edition */
- FSSpec tempSpec;
- Boolean myWasChanged;
- myErr = ResolveAlias(nil, ((*shortName)->fileAliasHandle), &tempSpec, &myWasChanged);
- myErr = NewSection(&myreply.container, &tempSpec, stPublisher, (*shortName)->windowID + gSectionID, pumOnSave,
- &gSecHandle);
-
- }
- if (!myErr) {
- /* put the section handle into our window structure */
- (*gSecHandle)->refCon = kNeverSaved; /* meaning that this _document_ has not been saved */
- /* put what type of thing this is in the refcon of the section handle */
- switch (typeToMake) {
- /* This is a little kludgy because I want to */
- case 'PICT':
- (*gSecHandle)->refCon = kPictType;
- break;
- case 'TEXT':
- (*gSecHandle)->refCon = kTextType;
- break;
- }
- StorePublisher(shortName, gSecHandle, &(*shortName)->selectionRect, pubText, typeToMake);
- }
- /* now write the data to the container */
- MyWriteSection(gSecHandle, theData, typeToMake);
- HUnlock(theData);
- switch (typeToMake) {
- case 'PICT':
- KillPicture((PicHandle)theData);
- break;
- case 'TEXT':
- break;
- case kCustomType:
- break;
- }
- (*shortName)->hasSelection = false;
- InvalRect(&(*shortName)->selectionRect); /* get rid of border once publish has happened */
- gShowPub = false;
- (*shortName)->hasSelection = false;
- SetMyCursor(0);
- SwitchChecks(kSelectStuff);
- HUnlock((Handle)shortName);
- }
-
- /* end CreatePublisher */
-
- /* MyUpdateEdition publishes the latest data for this edition. This will
- * be called when the user selects 'Send Edition Now' from the options
- * dialog, or when the document is saved (if automatic saving is
- * enabled), or if a section write AppleEvent happens
- */
- OSErr MyUpdateEdition(SectionHandle theSection)
- {
- WindowPtr tempCurrentWindow;
- WindowPtr tempWindow;
- Boolean tempSub, tempPub;
- windowCHandle shortName;
- SectionHandle *tempPtr;
- register qq;
- Rect *tempRectPtr;
- extern Rect gShowPubRect;
- extern Rect gShowSubRect;
- GetPort(&tempWindow);
- tempCurrentWindow = gCurrentWindow;
- if (((*theSection)->refCon & 0xf) == kPictType) {
- gCurrentWindow = FindSection(theSection);
- HLock((Handle)theSection);
- /* kill the borders, if any are showing right now */
- tempSub = gShowSub;
- tempPub = gShowPub;
- if (gShowSub)
- InvalRect(&gShowSubRect);
- if (gShowPub)
- InvalRect(&gShowPubRect);
- gShowSub = gShowPub = false;
- SetPort(gCurrentWindow);
- shortName = (windowCHandle)GetWRefCon(gCurrentWindow);
- HLock((Handle)shortName);
- (ProcPtr)((*shortName)->drawMe)(shortName, gCurrentWindow); /* draw without borders */
- /* search this window for the section asked for */
- HLock((*shortName)->pubs);
- tempPtr = (SectionHandle *)*(*shortName)->pubs;
- for (qq = 0; qq < (*shortName)->numPubs; qq++) {
- HLock((Handle)*tempPtr);
- if ((*theSection)->sectionID == (*(*tempPtr))->sectionID) {
- PicHandle tempPic;
- /* it's this one, grab the rect, pic it, publish it, and go away */
- HLock((*shortName)->pubRects);
- tempRectPtr = (Rect *)*(*shortName)->pubRects;
- tempRectPtr += qq;
- tempPic = MyMakePicture(tempRectPtr);
- HUnlock((*shortName)->pubRects);
- MyWriteSection(*tempPtr, (Handle)tempPic, 'PICT');
- KillPicture(tempPic);
- HUnlock((Handle)*tempPtr);
- break;
- }
- }
- HUnlock((Handle)theSection);
- HUnlock((Handle)shortName);
- } else {
- textSectionHandle theTS = TextSectionFromSecHandle(theSection);
- /* it's a text pub */
- MyWriteSection(theSection, (*theTS)->theText, 'TEXT');
-
- }
- InvalRect(&gCurrentWindow->portRect);
- gCurrentWindow = tempCurrentWindow;
- SetPort(tempWindow);
- return(noErr);
- }
-
- /* end MyUpdateEdition */
-
- /* MyMakePicture is a handy place to create our PICT demo data item.
- * It's called to create the actual edition data as well as the 'preview'
- * picture.
- */
- PicHandle MyMakePicture(Rect *thisRect)
- {
- PicHandle thepic;
- windowCHandle drawers;
- Boolean tempPub, tempSub;
- RgnHandle tempClip;
- /* make sure borders aren't included in the picture */
- tempPub = gShowPub;
- tempSub = gShowSub;
- gShowPub = false;
- gShowSub = false;
- tempClip = NewRgn();
- GetClip(tempClip);
- ClipRect(thisRect);
- thepic = OpenPicture(thisRect);
- drawers = (windowCHandle)GetWRefCon(gCurrentWindow);
- HLock((Handle)drawers);
- (ProcPtr)((*drawers)->drawMe)(drawers, gCurrentWindow);
- HUnlock((Handle)drawers);
- ClosePicture();
- SetClip(tempClip);
- DisposeRgn(tempClip);
- /* restore old border states */
- gShowPub = tempPub;
- gShowSub = tempSub;
- return(thepic);
- }
-
- /* end MyMakePicture */
-
- /* AEWriteSectionHandler is the AppleEvent handler for section write
- * events. It first pulls the SectionHandle out of the AppleEvent record,
- * then verifies that this is a registered section (still active, not canceled)
- * and then calls MyUpdateEdition to write the edition
- */
- pascal OSErr AEWriteSectionHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- #pragma unused (reply,refIn)
- SectionHandle theSection;
- OSErr myErr;
- myErr = GetSectionHandleFromEvent(messagein, &theSection);
- if (myErr = IsRegisteredSection((SectionHandle)theSection)) {
- ShowMe("\p Write IsRegisteredSection", myErr);
- return(myErr);
- }
- MyUpdateEdition(theSection);
-
- }
-
- /* end AEWriteSectionHandler */
- /* •••• NEW EVENT •••• */
- /* •• Please read the description and code in the Inside Mac vol VI chapters on */
- /* the Edition Manager and APpleEvents for a full description */
- /* AECreatePubHandler handles the new create publisher event */
-
- pascal OSErr AECreatePubHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- { windowCHandle tempWC;
- OSErr pubError = noErr;
- AliasHandle theAlias;
- Handle objectSpec;
- Size objectSize;
- DescType thisType;
- Size returnedSize;
- OSType theType;
- Boolean askForDialog;
- #define errAENoSuchObject 'noob'
- #define keyAEEditionFileLoc 'eloc'
- #define typeObjectSpecifier 'obj '
- /* this event has two parameters, a object specifier and an alias handle. */
- /* Both parameters are optional. */
- /* This sample application does not support the AppleEvents object model, so */
- /* we don't care about that parameter. */
- /* If you don't support the object model, then you need to check for a valid */
- /* current selection in the frontmost window */
- /* it's the same check we make to see if we should enable the 'Create Publisher' */
- /* menu item. */
- tempWC = (windowCHandle)GetWRefCon(FrontWindow());
- if (gHasSelection || HasTESelection(tempWC)){
- /* there is a valid selection. */
- /* get the alias handle from the event, if there is one */
- /* since we don't support the AE Object model yet, return an error if there is an object */
- /* spec contained in this event */
- pubError = AEGetParamPtr(messagein, keyDirectObject, typeObjectSpecifier, &thisType, (Ptr)&objectSpec,sizeof(Handle), &objectSize);
- if(pubError == noErr){
- /* no error means that there was an object specifier. That's Bad. return that we don't understand it */
- return(errAENoSuchObject);
- }
- pubError = AEGetParamPtr(messagein, keyAEEditionFileLoc, typeAlias, &thisType, (Ptr)&theAlias,sizeof(AliasHandle), &returnedSize);
- /* now pass to our publishing routine */
- if (HasTESelection(tempWC))
- theType ='TEXT';
- else
- theType ='PICT';
-
-
- pubError = CreatePublisher(theType,true,theAlias);
- } else {
- /* there was not a valid selection. Return the errAENoSuchObject error, since this */
- /* makes the most sense in this situation, and when you do implement the objects you */
- /* will already be prepared. Well, on one line of code at least.... */
- pubError= errAENoSuchObject;
- }
- return(pubError);
- }
- /* end AECreatePubHandler */
- /* AEScrollSectionHandler handles the scroll section event. You'll get this
- * event when the user clicks 'Open Publisher' either from the
- * Subcriber Options dialog, or from the Finder window.
- * This may also have happened after an ODOC AppleEvent, so
- * don't assume anything about your state that wouldn't be true
- * after an initial application launch
- */
- pascal OSErr AEScrollSectionHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- #pragma unused (reply,refIn)
- WindowPtr tempWindow;
- SectionHandle theSection;
- OSErr myErr;
- myErr = GetSectionHandleFromEvent(messagein, &theSection);
- tempWindow = FindSection(theSection);
- /* First bring our application to the front, then */
- /* treat this the same way you would a click in a back window */
- SetFrontProcess(&gOurSN);
- if (tempWindow != nil)
- ChangePlane(tempWindow);
- return(noErr);
- }
-
- /* end AEScrollSectionHandler */
-
- /* AECancelSectionHandler cancels a current section, either a publisher
- * or subscriber. This function pulls the section handle out of the
- * AppleEvent, then dispatches to the proper cancel routine for a
- * pub or sub.
- */
- pascal OSErr AECancelSectionHandler(AppleEvent *messagein, AppleEvent *reply, long refIn)
- {
- #pragma unused (reply,refIn)
- SectionHandle theSection;
- OSErr myErr;
- myErr = GetSectionHandleFromEvent(messagein, &theSection);
- myErr = IsRegisteredSection(theSection);
- if (myErr != noErr)
- return(myErr); /* already killed by someone */
- MyCancelSection(theSection, FindSection(theSection));
-
- }
-
- /* end AECancelSectionHandler */
-
- /* MyWriteSection actually opens and writes the section data. This will
- * be called in response to a click in 'Send Edition Now' in the pub options
- * box, from the section event 'write section', or when the file is being saved
- * and 'pumAuto' is enabled
- */
- OSErr MyWriteSection(SectionHandle secHandle, Handle theData, OSType theType)
- {
- OSErr myErr;
- /* update the time in the section handle please */
- /* this tells the Edition Manager that the eidtion has changed, and */
- /* to alert all the subscribers to the change */
- SetCursor(*GetCursor(watchCursor));
- HLock((Handle)secHandle);
- GetDateTime(&(*secHandle)->mdDate); /* ••• Please see NOTE in main.c about mdDate (find mdDate) */
- HUnlock((Handle)secHandle);
- /* OpenNewEdition, _NOT_ OpenEdition. You need to use OpenNewEdition */
- /* to get write access and to let the Edition Manager determine if you */
- /* are allowed to write to this section */
- myErr = OpenNewEdition(secHandle, 'CKH6', nil, &gEdRefNum);
- if (myErr)
- ShowMe("\pOpenNewEdition", myErr);
- HLock(theData);
- /* And actually write the data (finally) */
-
- myErr = WriteEdition(gEdRefNum, theType, *theData, GetHandleSize(theData));
- if (myErr)
- ShowMe("\pWriteEdition", myErr);
- if (myErr)
- myErr = 0;
- else
- myErr = -1;
- /* The Boolean tells the Edition Manager if you were successful in */
- /* writing the data. */
- myErr = CloseEdition(gEdRefNum, (Boolean)myErr);
- return(myErr);
- }
-
- /* end MyWriteSection */
-
- /* StorePublisher moves the window data struct storing function to here */
- /* shortName is locked on entry */
- void StorePublisher(windowCHandle shortName, SectionHandle storeSection, Rect *inRect, textSectionHandle textIn, OSType typeIn)
- {
- Rect *tempRectPtr;
- SectionHandle *tempPtr;
- OSErr myErr;
- switch (typeIn) {
- case 'PICT':
- HUnlock((*shortName)->pubs);
- MySetHandleSize((*shortName)->pubs, GetHandleSize((*shortName)->pubs) + sizeof(Handle));
- myErr = MemError();
- if (myErr)
- ShowMe("\pMemory", myErr);
- HLock((*shortName)->pubs);
- tempPtr = (SectionHandle *)((*(*shortName)->pubs) + (sizeof(Handle) * ((*shortName)->numPubs)));
- *tempPtr = (SectionHandle)storeSection;
- /* •••• NOTE, please look at the note in the Subscribe.c file concerning the dirty flag and */
- /* editions. Open Subscribe.c and find the string 'Human Interface' */
- /* (*shortName)->windowDirty = true; */
- /* save the rectangle to show the published rectangle if the user wants to see it. */
- HUnlock((*shortName)->pubRects);
- MySetHandleSize((*shortName)->pubRects, (GetHandleSize((*shortName)->pubRects) + sizeof(Rect)));
- myErr = MemError();
- if (myErr)
- ShowMe("\pMemory", myErr);
- HLock((*shortName)->pubRects);
- tempRectPtr = (Rect *)*(*shortName)->pubRects;
- tempRectPtr += (*shortName)->numPubs;
- *tempRectPtr = *inRect;
- (*shortName)->numPubs++;
- HUnlock((*shortName)->pubRects);
- HUnlock((*shortName)->pubs);
- break;
- case 'TEXT':
- /* set my text section ID to the same as the actual section ID, again, it keeps */
- /* dereferencing down */
- (*textIn)->theID = (*storeSection)->sectionID;
- /* tell myself that this is a publisher */
- (*textIn)->publishing = true;
- if ((*shortName)->textSections == nil) {
- (*shortName)->textSections = textIn;
- } else {
- textSectionHandle tempTS = (*shortName)->textSections;
- while ((*tempTS)->nextSection != nil) {
- tempTS = (*tempTS)->nextSection;
- }
- (*tempTS)->nextSection = textIn;
- }
- (*textIn)->theSection = storeSection;
- break;
- }
- gSectionID++;
- }
-
- /* Find Section returns the window that this section is included in */
- /* Need to look in both the PICT and TEXT lists */
- WindowPtr FindSection(SectionHandle inSection)
- {
- extern WindowPtr gActionWindows;
- extern short gWindowCount;
- long subIDtofind;
- Boolean secFound = false;
- SectionHandle *tempPtr;
- SectionRecord *tempRecord;
- Handle tempHandle;
- WindowPtr tempNextWindow;
- register qq, jj;
- subIDtofind = (*inSection)->sectionID;
- tempNextWindow = gActionWindows; /* start at the beginning of the chain */
- for (qq = 0; qq < gWindowCount; qq++) {
- windowCHandle tempWC;
- /* do housekeeping to get to the section handle list */
- tempWC = (windowCHandle)GetWRefCon(tempNextWindow);
- HLock((Handle)tempWC);
- if (((*inSection)->refCon & 0xf) == kPictType) {
- tempHandle = (*tempWC)->pubs; /* handle containing SectionHandles */
- HLock(tempHandle);
- tempPtr = (SectionHandle *)*tempHandle;
- /* Loop through all our sections until we find this edition */
- for (jj = 0; jj < (*tempWC)->numPubs; jj++) {
- HLock((Handle)*tempPtr);
- tempRecord = *(*tempPtr);
- if (tempRecord->sectionID == subIDtofind) {
- HUnlock((Handle)*tempPtr);
- HUnlock((Handle)tempWC);
- return(tempNextWindow);
- } else {
- HUnlock((Handle)tempWC);
- HUnlock((Handle)*tempPtr);
- tempPtr += 1;
- }
- }
- HUnlock(tempHandle);
- /* same thing for subscribers */
- tempHandle = (*tempWC)->subs; /* handle containing SectionHandles */
- HLock(tempHandle);
- tempPtr = (SectionHandle *)*tempHandle;
- /* Loop through all our sections until we find this edition */
- for (jj = 0; jj < (*tempWC)->numSubs; jj++) {
- HLock((Handle)*tempPtr);
- tempRecord = *(*tempPtr);
- if (tempRecord->sectionID == subIDtofind) {
- HUnlock((Handle)*tempPtr);
- HUnlock((Handle)tempWC);
- return(tempNextWindow);
- } else {
- HUnlock((Handle)tempWC);
- HUnlock((Handle)*tempPtr);
- tempPtr += 1;
- }
- }
- HUnlock(tempHandle);
- } else {
- /* Look in the TEXT lists */
- if ((*tempWC)->textSections) {
- textSectionHandle tempTS = (*tempWC)->textSections;
- do {
- if ((*((*tempTS)->theSection))->sectionID == subIDtofind) {
- HUnlock((Handle)tempWC);
- return(tempNextWindow);
- }
- tempTS = (*tempTS)->nextSection;
- } while (tempTS);
-
- }
- }
- tempNextWindow = (*tempWC)->nextWindow;
-
- HUnlock((Handle)tempWC);
- }
- return(nil);
- }
-
- pascal short ExpOptHook(short itemOffset, short itemHit, DialogPtr theDialog, Ptr yourDataPtr)
- {
- short myHit;
- short itemType;
- ControlHandle theButton;
- Rect theRect;
- /* first make sure that a sub-dialog is not frontmost */
- /* so we don't filter keys or hits to a sub-dialog */
- if (GetWRefCon((WindowPtr)theDialog) == 'stdf' || GetWRefCon((WindowPtr)theDialog) == 'optn') {
- /* only have one item in this expansion, but we'll check the range anyway */
- myHit = itemHit - itemOffset; /* since our item numbers are relative to the total number */
- /* of items in the dialog, and the system may change. Always do your item numbering based */
- /* on the offset, this will prevent incompatability when the system dialog grows or shrinks */
- if (myHit == 1) { /* I only added one item, so this be the one */
- /* Pass itemHit here, not myHit, since the dialog manager has no idea that this is an */
- /* additive dialog. It is counting from the actual start of the DITL, not the start of */
- /* your custom items */
- GetDialogItem(theDialog, itemHit, &itemType, (Handle *)&theButton, &theRect);
- if (GetControlValue(theButton))
- SetControlValue(theButton, false);
- else
- SetControlValue(theButton, true);
- }
- }
- return(itemHit); /* the return value must be absolute */
- }
-
- pascal Boolean ExpOptFilter(DialogPtr theDialog, EventRecord *theEvent, short itemOffset, short *itemHit, Ptr yourDataPtr)
- {
- short myHit;
- short itemType;
- ControlHandle theButton;
- Rect theRect;
- /* first make sure that a sub-dialog is not frontmost */
- /* so we don't filter keys or hits to a sub-dialog */
- if (GetWRefCon((WindowPtr)theDialog) == 'stdf' || GetWRefCon((WindowPtr)theDialog) == 'optn') {
- /* standard filter proc kinda stuff here */
- if ((theEvent->what) == keyDown) {
- char tempChar;
- tempChar = theEvent->message & charCodeMask;
-
- if (((tempChar == 'A') || (tempChar == 'a')) && (theEvent->modifiers & cmdKey)) {
- /* they pressed an A with the command key down, we get to handle it. */
- GetDialogItem(theDialog, itemOffset + 1, &itemType, (Handle *)&theButton, &theRect);
- if (GetControlValue(theButton))
- SetControlValue(theButton, false);
- else
- SetControlValue(theButton, true);
-
- return(true); /* tell folks we handled it */
- }
- }
- }
- return(false); /* was not a keystroke we wanted */
-
- }
-
- /* shortName is locked on entry */
- textSectionHandle GetTextSection(windowCHandle shortName, SectionType what)
- {
- CharsHandle theRawText;
- TEHandle tempTE;
- textSectionHandle theTextSection;
- short theLength;
- Handle theSelection;
- theTextSection = (textSectionHandle)NewHandle(sizeof(textSection));
- HLock((Handle)theTextSection);
- (*theTextSection)->bordered = gShowingAll; /* create section reflecting current */
- /* global border state */
- tempTE = (*shortName)->boxHandle;
- (*theTextSection)->startChar = (*tempTE)->selStart;
- if (what == stPublisher) {
- /* initialize it if it's a publisher */
- (*theTextSection)->endChar = (*tempTE)->selEnd;
-
- theRawText = TEGetText(tempTE);
- theSelection = NewHandle(((*tempTE)->selEnd) - ((*tempTE)->selStart));
-
- HLock(theSelection);
- HLock((Handle)theRawText);
- BlockMove((Ptr)*theRawText + (*tempTE)->selStart, (Ptr)*theSelection, (*tempTE)->selEnd - (*tempTE)->selStart);
- HUnlock(theSelection);
- HUnlock((Handle)theRawText);
- (*theTextSection)->theText = theSelection;
- } else {
- /* set start same as end for subscribers */
- (*theTextSection)->endChar = (*tempTE)->selStart;
- (*theTextSection)->theText = NewHandle(0);
- }
- (*theTextSection)->nextSection = nil;
- return(theTextSection);
- }
-
- textSectionHandle TextSectionFromSecHandle(SectionHandle theSection)
- {
- windowCHandle tempWC = (windowCHandle)GetWRefCon(FindSection(theSection)); /* gets the window it's in */
- textSectionHandle tempTS = (*tempWC)->textSections;
- unsigned long idToFind;
-
- idToFind = (*theSection)->sectionID;
- /* find the ID that matches this thang */
- do {
- if ((*tempTS)->theID == idToFind)
- return(tempTS);
- tempTS = (*tempTS)->nextSection;
- } while (tempTS);
- return(nil); /* failed */
- }
-
-
- #undef __PUBLISH__
-